package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.support.PageResult;
import com.itheima.support.QueryPageBean;
import com.itheima.mapper.CheckItemMapper;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import org.apache.dubbo.config.annotation.Service;

import java.util.List;

@Service
public class CheckItemServiceImpl extends ServiceImpl<CheckItemMapper, CheckItem> implements CheckItemService {
    @Override
    public boolean deleteById(Long id) {
        //1.先查询对象
        CheckItem checkItem = baseMapper.selectById(id);
        if(checkItem != null){
            checkItem.setDeleteFlag(1);
        }
        return this.updateById(checkItem);
    }

    @Override
    public List<CheckItem> findAll() {
        QueryWrapper<CheckItem> queryWrapper = new QueryWrapper<CheckItem>();
        queryWrapper.eq("delete_flag",0);
        return this.list(queryWrapper);
    }

    @Override
    public PageResult findByPage(QueryPageBean pageBean) {
        IPage<CheckItem> pageObj = new Page<>(pageBean.getCurrentPage(),pageBean.getPageSize());
        this.page(pageObj);
        return new PageResult(pageObj.getTotal(),pageObj.getRecords());
    }

    @Override
    public List<CheckItem> findByGroupId(Long groupId) {
        return this.baseMapper.findByGroupId(groupId);
    }
}
